import { ref } from 'vue';
import { useTable, LIST_TYPE } from '@crud/index';
import { getLecList } from '@/api/crm-agency/ad/lecturer';

export const useData = () => {
  // 产品列表
  const productOptions = ref([
    { label: '单日卡', value: 'W0T1' },
    { label: '三日卡', value: 'W0T3' },
    { label: '五日卡', value: 'W0T5' },
    { label: '周卡', value: 'W1T1' },
    { label: '双周卡', value: 'W2T1' },
    { label: '月卡', value: 'M1T1' }
  ]);

  // 渠道
  const channelOptions = ref([
    // { label: '微信', value: 1 },
    // { label: '抖音', value: 2 },
    { label: 'Web', value: 3 },
    { label: 'H5', value: 4 }
  ]);

  return { productOptions, channelOptions };
};
// 查询

// 表格
export const useTableList = (options: any = {}) => {
  const columns: any = [
    { label: '排名', prop: 'rank', width: 100, fixed: 'left' },
    { label: '讲师名称', prop: 'name', minWidth: 160, tooltip: true },
    { label: '讲师手机号', prop: 'mobile', minWidth: 120 },
    { label: '推广链接', prop: 'extend_url_cnt', minWidth: 120, render: 'extend_url_cnt' },
    { label: '绑定总数', prop: 'bind_cnt', minWidth: 120, render: 'bind_cnt' },
    { label: '佣金总数', prop: 'cos_fee', minWidth: 120, render: 'cos_fee' },
    { label: '昨日绑定数', prop: 'y_bind_cnt', minWidth: 120, render: (s: any) => s.row.y_bind_cnt || 0, sortable: 'custom' },
    { label: '近7日绑定数', prop: 'day7_bind_cnt', minWidth: 120, render: (s: any) => s.row.day7_bind_cnt || 0, sortable: 'custom' },
    { label: '跟进人', prop: 'follower', minWidth: 120, render: (s: any) => s.row.follower || '--' },
    { label: '操作', align: 'center', width: 120, render: 'actions', fixed: 'right' }
  ];
  const timeChange = (values: any[]) => {
    let from = undefined;
    let to = undefined;
    if (values && values.length > 0) {
      from = values[0];
      to = values[1];
    }
    return { from, to };
  };
  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      keyword: undefined,
      from_dt: undefined,
      to_dt: undefined,
      extend_type: 4,
      _dateRange: []
    },
    columns: columns,
    getParams: (params: Record<string, any>) => {
      const { _dateRange } = params;
      const { from, to } = timeChange(_dateRange);
      return {
        ...params,
        from_dt: from,
        to_dt: to,
        _dateRange: undefined
      };
    },
    getList: getLecList
  });
};
